home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / util.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  5KB  |  250 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "object.h"
  13. #include "paintop.h"
  14.  
  15. extern F_compound    objects;
  16.  
  17. /***********  The following extern vars for undo purpose  **************/
  18.  
  19.  
  20. extern int        pointmarker_shown;
  21.  
  22. static u_int    marker_pattern[] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  23. 0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff};
  24. mpr_static(pmarker, 5, 5, 1, marker_pattern);
  25.  
  26. tail(ob, tails)
  27. F_compound    *ob, *tails;
  28. {
  29.     F_arc        *a;
  30.     F_compound    *c;
  31.     F_ellipse    *e;
  32.     F_line        *l;
  33.     F_spline    *s;
  34.     F_text        *t;
  35.  
  36.     if (NULL != (a = ob->arcs)) for (; a->next != NULL; a = a->next);
  37.     if (NULL != (c = ob->compounds)) for (; c->next != NULL; c = c->next);
  38.     if (NULL != (e = ob->ellipses)) for (; e->next != NULL; e = e->next);
  39.     if (NULL != (l = ob->lines)) for (; l->next != NULL; l = l->next);
  40.     if (NULL != (s = ob->splines)) for (; s->next != NULL; s = s->next);
  41.     if (NULL != (t = ob->texts)) for (; t->next != NULL; t = t->next);
  42.  
  43.     tails->arcs = a;
  44.     tails->compounds = c;
  45.     tails->ellipses = e;
  46.     tails->lines = l;
  47.     tails->splines = s;
  48.     tails->texts = t;
  49.     }
  50.  
  51. /*
  52. Make pointers in tails point to the last element of each list of l1
  53. and Append the lists in l2 after those in l1.
  54. The tails pointers must be defined prior to calling append.
  55. */
  56. append_objects(l1, l2, tails)
  57. F_compound    *l1, *l2, *tails;
  58. {
  59.     if (tails->arcs)
  60.         tails->arcs->next  = l2->arcs; 
  61.     else
  62.         l1->arcs  = l2->arcs; 
  63.     if (tails->compounds)
  64.         tails->compounds->next  = l2->compounds;
  65.     else
  66.         l1->compounds  = l2->compounds;
  67.     if (tails->ellipses)
  68.         tails->ellipses->next  = l2->ellipses;
  69.     else
  70.         l1->ellipses  = l2->ellipses;
  71.     if (tails->lines)
  72.         tails->lines->next  = l2->lines;
  73.     else
  74.         l1->lines  = l2->lines;
  75.     if (tails->splines)
  76.         tails->splines->next  = l2->splines;
  77.     else
  78.         l1->splines  = l2->splines;
  79.     if (tails->texts)
  80.         tails->texts->next  = l2->texts;
  81.     else
  82.         l1->texts  = l2->texts;
  83.     }
  84.  
  85. /* Cut is the dual of append. */
  86.  
  87. cut_objects(objects, tails)
  88. F_compound    *objects, *tails;
  89. {
  90.     if (tails->arcs)
  91.         tails->arcs->next = NULL;
  92.     else
  93.         objects->arcs = NULL;
  94.     if (tails->compounds)
  95.         tails->compounds->next = NULL;
  96.     else
  97.         objects->compounds = NULL;
  98.     if (tails->ellipses)
  99.         tails->ellipses->next = NULL;
  100.     else
  101.         objects->ellipses = NULL;
  102.     if (tails->lines)
  103.         tails->lines->next = NULL;
  104.     else
  105.         objects->lines = NULL;
  106.     if (tails->splines)
  107.         tails->splines->next = NULL;
  108.     else
  109.         objects->splines = NULL;
  110.     if (tails->texts)
  111.         tails->texts->next = NULL;
  112.     else
  113.         objects->texts = NULL;
  114.     }
  115.  
  116. no_object()
  117. {
  118.     if (objects.texts != NULL) return(0);
  119.     if (objects.lines != NULL) return(0);
  120.     if (objects.ellipses != NULL) return(0);
  121.     if (objects.splines != NULL) return(0);
  122.     if (objects.arcs != NULL) return(0);
  123.     if (objects.compounds != NULL) return(0);
  124.     return(1);
  125.     }
  126.  
  127. show_pointmarker()
  128. {
  129.     if (pointmarker_shown) return;
  130.     pointmarker_shown = 1;
  131.     toggle_pointmarker();
  132.     }
  133.  
  134. erase_pointmarker()
  135. {
  136.     if (! pointmarker_shown) return;
  137.     pointmarker_shown = 0;
  138.     toggle_pointmarker();
  139.     }
  140.  
  141. toggle_pointmarker()
  142. {
  143.     F_ellipse    *e;
  144.     F_arc        *a;
  145.     F_line        *l;
  146.     F_spline    *s;
  147.  
  148.     for (e = objects.ellipses; e != NULL; e = e->next) {
  149.         toggle_ellipsepointmarker(e);
  150.         }
  151.     for (a = objects.arcs; a != NULL; a = a->next) {
  152.         toggle_arcpointmarker(a);
  153.         }
  154.     for (l = objects.lines; l != NULL; l = l->next) {
  155.         toggle_linepointmarker(l);
  156.         }
  157.     for (s = objects.splines; s != NULL; s = s->next) {
  158.         toggle_splinepointmarker(s);
  159.         }
  160.     }
  161.  
  162. toggle_ellipsepointmarker(e)
  163. F_ellipse    *e;
  164. {
  165.     set_marker(canvas_pixwin, e->start.x-2, e->start.y-2, 5, 5, INV_PAINT,
  166.         &pmarker, 0, 0);
  167.     set_marker(canvas_pixwin, e->end.x-2, e->end.y-2, 5, 5, INV_PAINT,
  168.         &pmarker, 0, 0);
  169.     }
  170.  
  171. toggle_arcpointmarker(a)
  172. F_arc    *a;
  173. {
  174.     set_marker(canvas_pixwin, a->point[0].x-2, a->point[0].y-2, 5, 5,
  175.         INV_PAINT, &pmarker, 0, 0);
  176.     set_marker(canvas_pixwin, a->point[1].x-2, a->point[1].y-2, 5, 5,
  177.         INV_PAINT, &pmarker, 0, 0);
  178.     set_marker(canvas_pixwin, a->point[2].x-2, a->point[2].y-2, 5, 5,
  179.         INV_PAINT, &pmarker, 0, 0);
  180.     }
  181.  
  182. toggle_linepointmarker(l)
  183. F_line    *l;
  184. {
  185.     F_point    *p;
  186.     int    fx, fy, x, y;
  187.  
  188.     p = l->points;
  189.     fx = p->x;  fy = p->y;
  190.     for (p = p->next; p!= NULL; p = p->next) {
  191.         x = p->x;  y = p->y;
  192.         set_marker(canvas_pixwin, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
  193.         }
  194.     if (x != fx || y != fy) {
  195.         set_marker(canvas_pixwin, fx-2, fy-2, 5, 5, INV_PAINT, 
  196.             &pmarker, 0, 0);
  197.         }
  198.     }
  199.  
  200. toggle_splinepointmarker(s)
  201. F_spline    *s;
  202. {
  203.     F_point    *p;
  204.     int    fx, fy, x, y;
  205.  
  206.     p = s->points;
  207.     fx = p->x;  fy = p->y;
  208.     for (p = p->next; p!= NULL; p = p->next) {
  209.         x = p->x;  y = p->y;
  210.         set_marker(canvas_pixwin, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
  211.         }
  212.     if (x != fx || y != fy) {
  213.         set_marker(canvas_pixwin, fx-2, fy-2, 5, 5, INV_PAINT, 
  214.             &pmarker, 0, 0);
  215.         }
  216.     }
  217.  
  218. num_points(points)
  219. F_point    *points;
  220. {
  221.     int    n;
  222.     F_point    *p;
  223.  
  224.     for (p = points, n = 0; p != NULL; p = p->next, n++);
  225.     return(n);
  226.     }
  227.  
  228. set_marker(win,x,y,w,h,op,pix,z1,z2)
  229. struct Window * win;
  230. {
  231.  int i;
  232.  set_gmode(op);
  233.  for (i=0;i<h;i++)
  234.   {
  235.   Move(RastPort,x,y+i);
  236.   Draw(RastPort,x+w-1,y+i);
  237.   }
  238.  reset_gmode();
  239. }
  240.  
  241. #ifdef AMIGA
  242. bzero(ptr,x)
  243. char * ptr;
  244. int x;
  245. {
  246.  int i;
  247.  for (i=0;i<x;i++) *ptr++=0;
  248. }
  249. #endif
  250.